package com.cdut.hezhisu.dribbble.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.cdut.hezhisu.dribbble.R;
import com.cdut.hezhisu.dribbble.util.ScreenUtil;

/**
 * Created by Administrator on 2015/12/27 0027.
 */
public class CircleColorView extends View{
    private int color;
    private float radius;
    private Paint myPaint;
    private int mCx;
    private int mCy;
    public CircleColorView(Context context) {
        super(context);
    }

    public CircleColorView(Context context, AttributeSet attrs) {
        super(context, attrs);
        myPaint = new Paint();
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleColorView);//TypedArray是一个数组容器
        color = a.getColor(R.styleable.CircleColorView_color,0);
        radius = a.getDimension(R.styleable.CircleColorView_radius,0.0f);
        mCx = ScreenUtil.dip2px(context, radius);
        mCy = ScreenUtil.dip2px(context, radius);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        myPaint.setColor(color);
        canvas.drawCircle(ScreenUtil.dip2px(getContext(), 10),ScreenUtil.dip2px(getContext(), 10),radius,myPaint);
    }

    public void setColor(int color){
        this.color = color;
        this.invalidate();
    }

}
